//Copyright (C) 2005  Neale Clark
//
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package tat.mvc;

import java.io.File;

import javax.swing.DefaultListModel;

import tat.TATAppLegacyWrapper;

/**
 * This class is the controller object for the application. It takes requests
 * from the GUI and passes them on to the application object.
 */
public class TATController {

	private TATAppLegacyWrapper app; // Holds reference to application (Model)
	private TATFrame gui; // Holds reference to gui (View)

	// List Models for lists in GUI
	private javax.swing.DefaultListModel actLm = new DefaultListModel();
	private javax.swing.DefaultListModel ucLm = new DefaultListModel();
	private javax.swing.DefaultListModel claLm = new DefaultListModel();
	private javax.swing.DefaultListModel attLm = new DefaultListModel();

	// Relation
	private javax.swing.DefaultListModel classRelLm = new DefaultListModel();
	private javax.swing.DefaultListModel ucRelLm = new DefaultListModel();
	private javax.swing.DefaultListModel reqLm = new DefaultListModel();

	public TATController(final TATFrame gui) {

		this.gui = gui;
		app = new TATAppLegacyWrapper(this);

	}

	public TATAppLegacyWrapper getApp() {
		return app;
	}

	public void setApp(final TATAppLegacyWrapper app) {
		this.app = app;
	}

	public TATFrame getGui() {
		return gui;
	}

	public void setGui(final TATFrame gui) {
		this.gui = gui;
	}

	public javax.swing.DefaultListModel getActLm() {
		return actLm;
	}

	public void setActLm(final javax.swing.DefaultListModel actLm) {
		this.actLm = actLm;
	}

	// Relation

	public void setRelLm(final javax.swing.DefaultListModel relLm) {
		this.classRelLm = relLm;
	}

	public void seqClassRelLm(final javax.swing.DefaultListModel reqLm) {
		this.reqLm = reqLm;
	}

	public javax.swing.DefaultListModel getClassRelLm() {
		return classRelLm;
	}

	public javax.swing.DefaultListModel getReqLm() {
		return reqLm;
	}

	public javax.swing.DefaultListModel getUcLm() {
		return ucLm;
	}

	public void setUcLm(final javax.swing.DefaultListModel ucLm) {
		this.ucLm = ucLm;
	}

	public javax.swing.DefaultListModel getClaLm() {
		return claLm;
	}

	public void setClaLm(final javax.swing.DefaultListModel claLm) {
		this.claLm = claLm;
	}

	public javax.swing.DefaultListModel getAttLm() {
		return attLm;
	}

	public void setAttLm(final javax.swing.DefaultListModel attLm) {
		this.attLm = attLm;
	}

	// Method to get app to read file and return text to gui for display
	public void readFile(final File file) {
		app.setSor(file);
		String text = app.readFile();
		gui.tp.setText(text);
	}

	public void saveTxt(final File file) {
		app.saveTxt(file);
	}

	public void saveXML(final File file) {
		app.saveXML(file);
	}

	public void saveRequirementsReport(final File file) {
		app.saveRequirementsReport(file);
	}

	// Methods to create objects just pass to application

	public void createActor(final String name) {
		app.createActor(name);
	}

	public void createUseCase(final String name) {
		app.createUseCase(name);
	}

	public void createClass(final String name) {
		app.createClass(name);
	}

	public void createAttribute(final String cla, final String name) {
		app.createAttribute(cla, name);
	}

	public void createRequirement(final String value, final int position) {
		app.createTextRequirement(value, position);
	}

	public void createUcRequirement(final String value) {
		app.createDomRequirement(value);
	}

	public void createDomRequirement(final String value) {
		app.createUcRequirement(value);
	}

	public void createRelationRequirement(final String value) {
		app.createRelationRequirement(value);
	}


	public void createClassRelation(final String origin, final String destination,
			final String originMultiplicity, final String destinationMultiplicity,
			final String type, final boolean navigable, final boolean createRequirement) {
		app.createClassRelation(origin, destination, originMultiplicity,
				destinationMultiplicity, type, navigable, createRequirement);
	}

	public void deleteActor(final String name) {
		app.deleteActor(name);
	}

	public void deleteUseCase(final String name) {
		app.deleteUseCase(name);
	}

	public void deleteClass(final String name) {
		app.deleteClass(name);
	}

	public void deleteAttribute(final String cla, final String name) {
		app.deleteAttribute(cla, name);
	}

	public void deleteUCActorRelation(final String relationName){
		app.deleteUCActorRelation(relationName);
	}

	public void deleteDomainModelRelation(final String relationName){
		app.deleteDomainModelRelation(relationName);
	}

	public void deleteRequirement(final String name) {
		app.deleteRequirement(name);
	}

	public void editActor(final String name) {
		app.editActor(name);
	}

	public void editUseCase(final String name) {
		app.editUseCase(name);
	}

	public void editClass(final String name) {
		app.editClass(name);
	}

	public void editAttribute(final String cla, final String name) {
		app.editAttribute(cla, name);
	}

	public void editRequirement(final String name) {
		app.editRequirement(name);
	}

	public void showText() {
		app.showText();
	}

	public void showXML() {
		app.showXML();
	}

	public void showRequirementsReport() {
		app.showRequirementsReport();
	}

	public void displayClassAtts(final String cl) {
		app.getClassAtts(cl);
	}

	public void resetApplication() {
		app.resetApplication();
		actLm.clear();
		attLm.clear();
		claLm.clear();
		classRelLm.clear();
		reqLm.clear();
		ucLm.clear();
		ucRelLm.clear();
	}

	public javax.swing.DefaultListModel getClassLm() {
		return claLm;
	}

	public DefaultListModel getUCActorRelLm() {
		return ucRelLm;
	}

	public void createUCActorRelation(final String actor, final String useCase) {
		app.createUCActorRelation(actor, useCase);
	}

}